var app = getApp();
Page({
  data: {
    stu: {
      items: [],
      paginate: {}
    },
    prompt: {
      hidden: !0,
      icon: '../../../assets/images/iconfont-order-default.png',
      title: '您还没有相关的幼儿园登记信息',
      text: '一键点击进行幼儿园登记',
      gurl: '../../../../../pages/register/register',
      gtype: "redirect"
    },
    page: 1,
    limit: 10,
  },
  onLoad() {
    var that = this;
    var openid = wx.getStorageSync('openid');
    if (openid == "") {
      wx.redirectTo({
        url: '../../pages/index/index'
      })
    } else {
      that.getdata();
    }
  },

  getdata: function () {//定义函数名称
    var that = this;
    wx.showLoading({
      title: '加载中',
    })
    var wxid = wx.getStorageSync('openid');
    wx.request({
      url: app.myUlife.ulifeUrl + '/wechart/studentList.html',//请求地址
      data: {//发送给后台的数据
        page: that.data.page,
        limit: that.data.limit,
        wxid: wxid
      },
      header: {//请求头
        "Content-Type": "applciation/json"
      },
      method: "GET",//get为默认方法/POST
      success: function (res) {
        wx.hideLoading()
        //登记信息列表
        var stuarr = that.data.stu.items;
        var stu = res.data.items;
        
        for (var i = 0; i < stu.length; i++) {
          stuarr.push(stu[i]);
        }
        var paginate = res.data.paginate;
        var key1 = "stu.items";
        var key2 = "stu.paginate";
        var obj = {};
        obj[key1] = stuarr;
        obj[key2] = paginate;
        that.setData(obj);
        that.setData({
          'prompt.hidden': stuarr.length
        });

      },
      fail: function (err) { },//请求失败
      complete: function () { }//请求完成后执行的函数
    })
  },

  //上拉刷新
  tolower() {
    var that = this;
    var page = parseInt(that.data.page) + 1;
    that.setData({
      page: page
    });
    that.getdata();
  },



  //取消登记
  cancelBM(e) {
    var sfkqbm = wx.getStorageSync('sfkqbm');
    if (sfkqbm == "1") {
      wx.showModal({
        title: '温馨提示',
        content: '新生登记结束，等待摇号！',
        showCancel: !1,
      })
      return;
    }
    var sfbmcg = e.currentTarget.dataset.sfbmcg;
    if (sfbmcg==1){
      wx.showModal({
        title: '友情提示',
        content: '该小朋友已经登记成功,无法取消!',
        showCancel: !1,
      })
      return;
    }
    var that = this;
    wx.showModal({
      title: '提示',
      content: '取消登记后数据不可恢复,是否确定取消!',
      success(res) {
        if (res.confirm) {
          wx.showLoading({
            title: '删除中...',
          })
          var sid = e.currentTarget.dataset.sid;
          wx.request({
            url: app.myUlife.ulifeUrl + '/wechart/cancelBM.html',//请求地址 
            data: {
              sid: sid
            },
            header: {
              "Content-Type": "applciation/json"
            },
            method: "GET",//get为默认方法/POST
            success: function (res) {
              if (!res.data){
                wx.showModal({
                  title: '友情提示',
                  content: '取消失败,登记已经结束!',
                  showCancel: !1,
                })
              }else{

                that.setData({
                  stu: {
                    items: [],
                    paginate: {}
                  },
                  page: 1
                });

                that.getdata();
              } 
              wx.hideLoading()
            },
            fail: function (err) { },//请求失败
            complete: function () { }//请求完成后执行的函数
          })

        }
      }
    })


    
  }


})